package com.itheima.admin.controller;

import com.itheima.admin.dto.SensitivePageRequestDto;
import com.itheima.admin.pojo.AdSensitive;
import com.itheima.admin.service.AdSensitiveService;
import com.itheima.common.dto.PageRequestDto;
import com.itheima.common.vo.PageResultVo;
import com.itheima.common.vo.ResultVo;
import com.sun.org.apache.bcel.internal.generic.IF_ACMPEQ;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sensitive")
@Api(tags = "敏感词管理")
public class AdSensitiveController {

    @Autowired
    private AdSensitiveService adSensitiveService;

    @PostMapping("/list")
    @ApiOperation("分页查询")
    public PageResultVo<AdSensitive> findPage(@RequestBody SensitivePageRequestDto dto){
        PageResultVo<AdSensitive> vo = adSensitiveService.findPage(dto);
        return vo;
    }

    @PostMapping("/save")
    @ApiOperation("添加敏感词")
    public ResultVo save(@RequestBody AdSensitive adSensitive){
        if (adSensitiveService.save(adSensitive)){
            return ResultVo.ok();
        }
        return ResultVo.error();
    }

    @PostMapping("/update")
    @ApiOperation("修改敏感词")
    public ResultVo update(@RequestBody AdSensitive adSensitive){
        if (adSensitive.getId()==null){
            return ResultVo.error();
        }
        if (adSensitiveService.updateById(adSensitive)){
            return ResultVo.ok();
        }
        return ResultVo.error();
    }

    @PostMapping("/delete/{id}")
    @ApiOperation("移除敏感词")
    public ResultVo remove(@PathVariable Long id){
        if (adSensitiveService.removeById(id)){
            return ResultVo.ok();
        }
        return ResultVo.error();
    }
}
